import axios, { CreateAxiosDefaults } from 'axios'
import { setupInterceptors } from '@/utils/http/interceptors.ts'

export function createAxios(options: CreateAxiosDefaults = {}) {
  const defaultOptions: CreateAxiosDefaults = {
    baseURL: '/api',
    timeout: 60000,
  }

  const service = axios.create({
    ...defaultOptions,
    ...options,
  })
  setupInterceptors(service)
  return service
}

export const request = createAxios()
